<template>
    <el-container>
        <el-header>
            <div class="left-panel">
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    :disabled="!addState"
                    @click="exportExcel"
                >导出</el-button>
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    v-if="orgType==1"
                    @click="opAdd"
                >新增</el-button>
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    :disabled="!addState"
                    @click="opBatchSend"
                >供应商发货</el-button>
                <el-button
                    type="primary"
                    icon="el-icon-plus"
                    :disabled="!addState"
                    @click="batchReceive"
                    v-if="isBatchReceive"
                >供应商批量接单</el-button>
            </div>
            <div class="right-panel">
                <el-button :icon="Search"   type="primary" @click="opBindData">查询</el-button>
                <el-button :icon="Search" type="info" plain @click="resetSearch">重置</el-button>
                <el-button text type="primary" @click="showCondition = !showCondition">
                    <span v-if="!showCondition">展开</span>
                    <span v-else>收起</span>
                    <vab-icon
                        class="vab-dropdown"
                        :class="{ 'vab-dropdown-active': fold }"
                        icon="arrow-up-s-line"
                    />
                </el-button>
            </div>
        </el-header>
        <el-foot v-show="showCondition">
            <vab-query-form-top-panel>
                <el-form inline label-width="49px" :model="queryForm" style="margin-top: 5px">
                    <el-form-item label="订单编号" label-width="100px">
                        <el-input
                            placeholder="---请输入订单编号---"
                            v-model="queryList.purchaseOrderCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item v-if="orgType=='1'" label="要货订单号" label-width="100px">
                       <el-input
                           placeholder="---请输入要货订单号---"
                           v-model="queryList.applyOrderCode"
                           style="width: 300px"
                       />
                   </el-form-item>
				   <!-- <el-form-item v-if="orgType=='3'" label="要货订单号" label-width="100px">
				       <el-input
				           placeholder="---请输入要货订单号---"
				           v-model="queryList.applyOrderCode"
				           style="width: 300px"
				       />
				   </el-form-item> -->
                    <el-form-item label="申请单位" label-width="100px">
                        <!-- <sc-store-select
                            ref="orgselect"
                            :props="storeProps"
                            :selectKeyValue="'storeId'"
                            v-model="queryList.stores"
                            @fatherMethod="storeSelectProcess"
                            style="width: 300px"
                        ></sc-store-select> -->
                        <sc-auto-complete
                         :orgType="2"
                         :queryType="'store/search'"
                         :placeholder="'---请输入申请单位---'"
                         v-model="queryList.storeName"
                         @handleSelect="(e)=>{this.queryList.storeName=e.storeName}"
                        />
                    </el-form-item>

                    <el-form-item label="单据状态" label-width="100px">
                        <el-select
                            placeholder="---请选择状态---"
                            v-model="queryList.status"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsState"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="物料发货状态" label-width="100px">
                        <el-select
                            placeholder="---请选择物料发货状态---"
                            v-model="queryList.purchaseOrderSendStatus"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsPurchaseOrderSendStatus"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                    <el-form-item label="供应商名称" label-width="100px">
                        <!-- <el-input
                            placeholder="---请输入供应商名称---"
                            v-model="queryList.supplierName"
                            style="width: 300px"
                        /> -->
                        <sc-auto-complete
                         :orgType="3"
                         :queryType="'supplier/search'"
                         :placeholder="'---请输入供应商名称---'"
                         v-model="queryList.supplierName"
                         @handleSelect="(e)=>{this.queryList.supplierName=e.supplierName}"
                        />
                    </el-form-item>
                    <el-form-item label="下单人" label-width="100px">
                        <el-input
                            placeholder="---请输入下单人---"
                            v-model="queryList.createName"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料编码" label-width="100px">
                        <el-input
                            placeholder="---请输入物料编码---"
                            v-model="queryList.materialCode"
                            style="width: 300px"
                        />
                    </el-form-item>
                    <el-form-item label="物料名称" label-width="100px">
                        <el-input
                            placeholder="---请输入名称---"
                            v-model="queryList.materialName"
                            style="width: 300px"
                        />
                    </el-form-item>

                   <!-- <el-form-item label="下单时间" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.crDates"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                        />
                    </el-form-item> -->
                    <el-form-item label="采购时间" label-width="100px">
                        <el-date-picker
                            style="width: 300px"
                            v-model="queryList.purchaseDates"
                            type="datetimerange"
                            value-format="YYYY-MM-DD HH:mm:ss"
                            format="YYYY-MM-DD HH:mm:ss"
                            range-separator="-"
                            unlink-panels="true"
                            start-placeholder="开始时间"
                            end-placeholder="结束时间"
                            :default-time="defaultTime"
                        />
                    </el-form-item>
                    <el-form-item label="订单类型" label-width="100px">
                        <el-select
                            placeholder="---请选择订单类型---"
                            v-model="queryList.orderType"
                            style="width: 300px"
                        >
                            <el-option label="---请选择---" value />
                            <el-option
                                v-for="item in optionsPurchaseOrderType"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value"
                            />
                        </el-select>
                    </el-form-item>
                </el-form>
            </vab-query-form-top-panel>
        </el-foot>

        <el-main class="nopadding">
            <scTable
                ref="mytable"
                :queryType="'purchase-order/pages'"
                :data="listData"
                :queryList="queryList"
                :column="columnList"
                :orderList="OrderList"
                :sort-orders="['ascending', 'descending']"
                @selection-change="selectionChange"
               :row-class-name="setRowClass"
                :pageSize="10"
                :isKeyDown="showCondition" 
                row-key="purchaseOrderId"
                show-summary
                remoteSummary
            >
                <el-table-column type="selection" width="50"></el-table-column>
                <el-table-column label="采购时间" prop="purchaseDate" width="120" sortable>
                    <template #default="scope">{{scope.row.purchaseDate?.slice(0,10)}}</template>
                </el-table-column>
               
                <el-table-column label="申请单位" prop="storeName" width="220" sortable v-if="orgType==1"></el-table-column>
                <el-table-column label="采购单位" prop="storeName" width="220" sortable v-if="orgType==3"></el-table-column>
                <el-table-column label="订单编号" prop="purchaseOrderCode" width="200" sortable>
                    <template #default="scope"> <span class="el-span-text" @click="opShow(scope.row, scope.$index)">{{scope.row.purchaseOrderCode}}</span></template>
                </el-table-column>
                <el-table-column label="物料名称"  prop="materialDesc" width="140" sortable >
                    <template #default="scope">
                        <el-popover placement="bottom-start" :width="500" trigger="click">
                            <template #reference>
                                <div
                                    style="position: relative;text-overflow: ellipsis;white-space: nowrap;cursor: pointer;display: block;"
                                >
                                    <span v-for="item in scope.row.purchaseOrderItems" :key="item" style="color: #318cf3;">
                                        {{item.materialName}}/{{item.qty}}{{item.unitName}};
                                    </span>
                                </div>
                            </template>
                            <el-table :data="scope.row.purchaseOrderItems" style="width: 100%" stripe>
                                <el-table-column prop="materialName" label="物料名称" min-width="140" />
                                <el-table-column prop="qty" label="数量" min-width="80" />
                                <el-table-column prop="unitName" label="单位" min-width="80" />
                            </el-table>
                        </el-popover>
                    </template>
                </el-table-column>
                <!-- <el-table-column label="采购单价" prop="price" width="120" sortable v-if="orgType==1"></el-table-column> -->
                <!-- <el-table-column label="申请数量" prop="qty" width="120" sortable v-if="orgType==1"></el-table-column> -->
                <el-table-column :label="orgType==1?'集采下单数量':'下单数量'" prop="confirmQty" width="150" sortable>
                    <template #default="scope">
                        {{scope.row.confirmQty}}
                    </template>
                </el-table-column>
                <el-table-column label="供应商接单数量" prop="receiveQty" width="150" sortable>
                    <template #default="scope">
                        <span v-if="scope.row.status==2">/</span>
                        <span v-else>{{scope.row.receiveQty}}</span>
                    </template>
                </el-table-column>

                <el-table-column label="采购金额" prop="purchaseAmount" width="120" sortable>
                    <template #default="scope">{{scope.row.purchaseAmount?.toFixed(2)}}</template>
                </el-table-column>

                <el-table-column label="接单金额" prop="receiveAmount" width="120" sortable>
                    <template #default="scope">{{scope.row.receiveAmount?.toFixed(2)}}</template>
                </el-table-column>
                <el-table-column label="类型" prop="purchaseType" width="100" sortable>
                    <template #default="scope">{{scope.row.purchaseTypeDesc}}</template>
                </el-table-column>
                <el-table-column label="下单人" prop="createName" width="100" sortable></el-table-column>
                <el-table-column label="供应商" prop="supplierName" width="200" sortable></el-table-column>
                <el-table-column label="采购单位" prop="purchaseUnityName" width="120" sortable></el-table-column>
                <el-table-column label="物料发货状态" prop="sendStatusDesc" width="150" sortable >
                    <template #default="scope" >
                        <span v-if="scope.row.purchaseOrderType==0 && (scope.row.status==1||scope.row.status==2||scope.row.status==0)">/</span>
                        <span v-else-if="scope.row.purchaseOrderType==1 && scope.row.status==2">/</span>
                        <span v-else-if="scope.row.purchaseOrderType==2 && scope.row.status==2">/</span>
                        <span v-else>{{scope.row.sendStatusDesc}}</span>
                       <!-- <span v-else>待发货</span> -->
                    </template>
                </el-table-column>
                <el-table-column label="单据状态" prop="statusDesc" width="120" sortable></el-table-column>
                <el-table-column label="备注" prop="remarks" width="180" sortable></el-table-column>
               
                <el-table-column label="操作" fixed="right" align="right" width="300">
                    <template #default="scope">
                        <el-button-group>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                @click="opShow(scope.row, scope.$index)"
                            >查看</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="orgType==1&&scope.row.status==2"
                                @click="opCancel(scope.row, 3)"
                            >撤回</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.status==2"
                                @click="opReceive(scope.row, scope.$index)"
                            >接单</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="scope.row.status==3&&scope.row.sendStatus!=2"
                                @click="opSend(scope.row, scope.$index)"
                            >发货</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="orgType==1&&(scope.row.status==1||scope.row.status==0)"
                                @click="opEdit(scope.row, scope.$index)"
                            >编辑</el-button>              
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="orgType==1&&(scope.row.status==8||scope.row.status==0)&&scope.row.purchaseOrderType!=0"
                                @click="opConfirm(scope.row, scope.$index)"
                            >确认</el-button>
                            <el-button
                                text
                                type="primary"
                                size="small"
                                v-show="(scope.row.status==3||scope.row.status==5)&&scope.row.sendStatus!=0"
                                @click="opSendDetail(scope.row, scope.$index)"
                            >发货明细</el-button>
                            <el-button
                                text
                                type="warning"
                                size="small"
                                v-show="scope.row.purchaseType==1 && scope.row.taskStatus==0 && scope.row.sendStatus!=0"
                                @click="opTask(scope.row, scope.$index)"
                            ><el-icon><Sell /></el-icon>收货</el-button>
                        </el-button-group>
                    </template>
                </el-table-column>
            </scTable>
        </el-main>

    </el-container>

    <save-dialog
        v-if="dialogSave"
        ref="saveDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogSave = false"
    ></save-dialog>

    <detail-dialog
        v-if="dialogDetail"
        ref="detailDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogDetail = false"
    ></detail-dialog>

    <receive-dialog
        v-if="receiveSave"
        ref="receiveDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="receiveSave = false"
    ></receive-dialog>

    <send-dialog
        v-if="dialogSend"
        ref="sendDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogSend = false"
    ></send-dialog>

    <send-detail-dialog
        v-if="dialogSendDetail"
        ref="sendDetailDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogSendDetail = false"
    ></send-detail-dialog>

    <confirm-dialog
        v-if="confirmSave"
        ref="confirmDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="confirmSave = false"
    ></confirm-dialog>

    <apply-detail-dialog
        v-if="dialogApplyDetail"
        ref="applyDetailDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogApplyDetail = false"
    ></apply-detail-dialog>

    <task-dialog
        v-if="dialogTask"
        ref="taskDialog"
        @fatherMethod="opBindData"
        @success="handleSaveSuccess"
        @closed="dialogTask = false"
    ></task-dialog>
</template>

<script>

import saveDialog from "./selfSave";
import tool from "@/utils/tool";
import applyDetailDialog from "../../../apply/order/detail";
import confirmDialog from "./confirm";
import detailDialog from "./selfDetail";
import receiveDialog from "./receive";
import sendDialog from "./send";
import sendDetailDialog from "./sendDetail";
import taskDialog from "./task";
import publicjs from "@/api/model/publicjs";

export default {
    name: "posInfo-room",
    components: {
        applyDetailDialog,
        confirmDialog,
        saveDialog,
        detailDialog,
        sendDialog,
        sendDetailDialog,
        receiveDialog,
        taskDialog,
        publicjs,
    },
    data() {
        return {
            isBatchReceive:false,
            dialogApplyDetail:false,
            confirmSave:false,
            dialogSave:false,
            orgType: 0,
            dialogDetail: false,
            receiveSave: false,
            dialogSend: false,
            dialogSendDetail: false,
            dialogTask:false,
            showCondition: false,
            selectionRows: [],
            pkList: ["purchaseOrderId"],
            columnList: [],
            OrderList: { purchaseOrderId: "Asc" },
            queryList: {},
            defaultQuery: {"purchaseOrderType":[0],purchaseTypes:[1,2,3,4]},
            result: "", // 运行结果
            props1: {
                checkStrictly: true,
                emitPath: false,
            },
            supplierProps: {
                label: "supplierName",
                value: "supplierId",
            },
            storeProps: {
                label: "storeName",
                value: "storeId",
            },
            addState: true, //可以增加
            editState: true, //可以修改
            editBatchState: true, //可以批量修改
            deleteState: true, //可以删除
            optionsState: [],
            optionsPurchaseOrderSendStatus:[],
            materialTypeTree: [],
            optionsPurchaseOrderType:[],//订单类型
            selectedRow:[],
            defaultTime:[
                new Date(2000, 1, 1, 0, 0, 0),
                new Date(2000, 2, 1, 23, 59, 59),
            ]
        };
    },
    methods: {
        //查看要货订单详情
        opApplyShow(row) {
            this.dialogApplyDetail = true;
            this.$nextTick(() => {
                this.$refs.applyDetailDialog.setData(row);
                this.$refs.applyDetailDialog.open("Show");
            });
        },
        //添加
        opAdd() {
            this.dialogSave = true;
            this.$nextTick(() => {
                this.$refs.saveDialog.setData({});
                this.$refs.saveDialog.open("Add");
            });
        },
        //编辑
        opEdit(row) {
            this.dialogSave = true;
            this.$nextTick(() => {
                this.$refs.saveDialog.setData(row);
                this.$refs.saveDialog.open("Edit");
            });
        },
        //复制
        opCopy(row) {
            this.dialogSave = true;
            this.$nextTick(() => {
                this.$refs.saveDialog
                    .open("Add")
                    .setData({ ...row, purchaseProtocolCode: "" });
            });
        },
        //接单
        opReceive(row) {
            this.receiveSave = true;
            this.$nextTick(() => {
                this.$refs.receiveDialog.setData(row);
                this.$refs.receiveDialog.open("Add");
            });
        },
        //确认
        opConfirm(row) {
            this.confirmSave = true;
            this.$nextTick(() => {
                this.$refs.confirmDialog.setData(row);
                this.$refs.confirmDialog.open("Add");
            });
        },
        //发货
        opSend(row) {
            this.dialogSend = true;
            this.$nextTick(() => {
                this.$refs.sendDialog.setData([row.purchaseOrderId]);
                this.$refs.sendDialog.open("Send");
            });
        },
        //退款
        async opRefund(row){
            try {
                var returnValue = await this.$API.auth.GetProcessApi.get(
                    "purchase-order/refund/"+row.purchaseOrderId,
                    { }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //批量发货
        opBatchSend() {
            if (this.selectionRows.length == 0) {
                this.$message.success("请选择要发货的订单");
                return;
            }
            const storeId = this.selectionRows[0].storeId;
            let sendState = true;
            this.selectionRows.forEach((element) => {
                //未接单无法发货
                if (element.status != 3) {
                    this.$message.error(`【${element.purchaseOrderCode}】该要货单无法发货`);
                    sendState = false;
                    return;
                }

                //已全部发货完成
                if (element.sendStatus == 2) {
                    this.$message.error( `【${element.purchaseOrderCode}】该要货单已全部发货`);
                    sendState = false;
                    return;
                }

                if (element.storeId != storeId) {
                    this.$message.error("请选择相同的要货单位订单");
                    sendState = false;
                    return;
                }
            });
            if (sendState) {
                const purchaseOrderIds = this.selectionRows.map(
                    (p) => p.purchaseOrderId
                );
                this.dialogSend = true;
                this.$nextTick(() => {
                    this.$refs.sendDialog.setData(purchaseOrderIds);
                    this.$refs.sendDialog.open("Send");
                });
            }
        },
        //发货明细
        opSendDetail(row) {
            this.dialogSendDetail = true;
            this.$nextTick(() => {
                this.$refs.sendDetailDialog.setData(row.purchaseOrderId);
                this.$refs.sendDetailDialog.open("Send");
            });
        },
        //收货
        opTask(row)
        {
            this.dialogTask = true;
            this.$nextTick(() => {

                this.$refs.taskDialog.setData(row.purchaseOrderId);
                this.$refs.taskDialog.open("Task");
            });
        },
        //查看
        opShow(row) {
            this.dialogDetail = true;
            this.$nextTick(() => {
                this.$refs.detailDialog.open("Show").setData(row);
            });
        },
        //设置状态
        async setStatus(row) {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    row.status == 0
                        ? "purchase-order/disabled"
                        : "purchase-order/enable",
                    { purchaseOrderIds: [row.purchaseOrderId] }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //批量接单
        async batchReceive() {
            this.$confirm(
                `确定批量接单选中的 ${this.selectionRows.length} 项吗？`,
                "提示",
                {
                    type: "warning",
                }
            )
                .then(async () => {
                    const purchaseOrderIds = this.selectionRows.map(
                        (p) => p.purchaseOrderId
                    );
                    try {
                        var returnValue =
                            await this.$API.auth.PostProcessApi.post(
                                "purchase-order/batch-receive-ids",
                                { purchaseOrderIds: [...purchaseOrderIds] }
                            );
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$refs.mytable.getData();
                        } else {
                            this.$message.error("操作失败:" + returnValue.msg);
                        }
                    } catch (error) {
                        this.loading = false;
                        return false;
                    }
                })
                .catch(() => {});
            
        },
        //撤单
        async opCancel(row,stauts) {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post("purchase-order/cancel",
                    { purchaseOrderId:row.purchaseOrderId,status:stauts}
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //终止
        async opClose(row,stauts)
        {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post("purchase-order/close",
                    { purchaseOrderId:row.purchaseOrderId,status:stauts}
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //删除
        async opDelete(row) {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "purchase-order/delete",
                    { purchaseOrderIds: [row.purchaseOrderId] }
                );
                if (returnValue.status == 200) {
                    this.$message.success("操作成功");
                    this.$refs.mytable.getData();
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        setRowClass({ row }) {
            if (this.selectionRows.includes(row)) {
                return "selected-row-color";
            }
            return "";
        },
        //表格选择后回调事件
        selectionChange(selection) {
            this.selectionRows = selection;
        },
        //本地更新数据
        handleSaveSuccess(data, mode) {
            if (mode == "Add") {
                this.$refs.mytable.refresh();
            } else if (mode == "Edit") {
                this.$refs.mytable.refresh();
            }
        },
        async opBindData() {
            this.$refs.mytable.clearSort();
            this.$refs.mytable.getData();
        },
        resetSearch() {
            this.queryList = {...this.defaultQuery};
        },
        async initOptions() {
            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "base-dictionary/options",
                    { Codes: ["PurchaseOrderStatus","PurchaseOrderSendStatus","OrderType"] }
                );
                if (returnValue.status == 200) {
                    this.optionsState = returnValue.response.find(
                        (p) => p.code == "PurchaseOrderStatus"
                    ).optionsDetails;

                    this.optionsPurchaseOrderSendStatus = returnValue.response.find(
                        (p) => p.code == "PurchaseOrderSendStatus"
                    ).optionsDetails;

                    this.optionsPurchaseOrderType = returnValue.response.find(
                        (p) => p.code == "OrderType"
                    ).optionsDetails;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }

            try {
                var returnValue = await this.$API.auth.PostProcessApi.post(
                    "material-type/tree",
                    { status: 1 }
                );
                if (returnValue.status == 200) {
                    this.materialTypeTree = returnValue.response;
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        //供应商
        async supplierSelectProcess(rowData) {
            this.queryList.suppliers = [];
            this.queryList.supplierIds = [];
            if (rowData && rowData.length > 0) {
                rowData.map((p, index) => {
                    if (p) {
                        debugger;
                        this.queryList.suppliers = [
                            ...this.queryList.suppliers,
                            {
                                supplierId: p.supplierId,
                                supplierName: p.supplierName,
                            },
                        ];
                        this.queryList.supplierIds = [
                            ...this.queryList.supplierIds,
                            p.supplierId,
                        ];
                    }
                });
            }
            await this.opBindData();
        },
        //店铺
        async storeSelectProcess(rowData) {
            this.queryList.stores = [];
            this.queryList.storeIds = [];
            if (rowData && rowData.length > 0) {
                rowData.map((p, index) => {
                    if (p) {
                        debugger;
                        this.queryList.stores = [
                            ...this.queryList.stores,
                            {
                                storeId: p.storeId,
                                storeName: p.storeName,
                            },
                        ];
                        this.queryList.storeIds = [
                            ...this.queryList.storeIds,
                            p.storeId,
                        ];
                    }
                });
            }
            await this.opBindData();
        },
        //导出
        async exportExcel() {
            try {
                var response = await this.$API.auth.PostDownApi.post(
                    "purchase-order/export",
                    this.queryList
                );
                // 获取 Content-Disposition 头部信息
                debugger;
                const headers = new Headers(response.headers);
                console.log(headers);
                let fileName = headers.get("File-Name");
                console.log(fileName);
                fileName = decodeURIComponent(fileName);
                console.log(fileName);
                if (!fileName || fileName == "null") {
                    fileName = "采购订单.xlsx";
                }
                console.log(fileName);
                const blob = new Blob([response.data], {
                    type: "application/xlsx",
                });
                // 创建一个临时的 URL 对象，指向下载的 Blob 数据
                const url = window.URL.createObjectURL(blob);
                // 创建一个 <a> 元素，设置其 href 属性为 URL，并触发点击
                const a = document.createElement("a");
                a.href = url;
                a.download = fileName; // 下载时显示的文件名为从头信息中获取的文件名
                document.body.appendChild(a); // 将 <a> 元素添加到 DOM 中
                a.click(); // 模拟点击下载
                document.body.removeChild(a); // 下载完成后移除 <a> 元素
                window.URL.revokeObjectURL(url); // 释放 Blob 对象
            } catch (error) {
                this.loading = false;
                this.$alert(error.message, "提示", { type: "error" });
                return false;
            }
        },
        async formatDate(date) {
            if (date) {
                const dateNew = tool.formatDate(new Date(date), 1);
                console.log(dateNew);
            }
            return "";
        },
    },
    async mounted() {
        this.orgType = tool.data.get("USER_INFO").AccountType;
        var purchaseOrderCode=this.$route.query.purchaseOrderCode;

        // if(!this.defaultQuery||this.orgType==1){
        //     this.isBatchReceive=true;
        //     this.defaultQuery={...this.defaultQuery,"purchaseOrderType":[0]}
        // }
       this.queryList={...this.defaultQuery};
        if(purchaseOrderCode){
            this.queryList.purchaseOrderCode=purchaseOrderCode
        }
        console.log('queryList',this.queryList)
        await this.initOptions();
        await this.opBindData();
    },
};
</script>
<style lang="scss" scoped>
/* 当表格行处于悬停状态时改变背景颜色 */
::v-deep .el-table .el-table__row:hover {
    background-color: #dae8f7;
}
::v-deep .el-table__body .el-table__row--striped.hover-row td {
    background-color: #dae8f7 !important;
}
//   斑马纹选中颜色
::v-deep .el-table__body .el-table__row--striped.selected-row-color td {
    background-color: #b8dcff !important;
}
::v-deep .el-table {
    --el-table-row-hover-bg-color: #dae8f7;
}
::v-deep .el-table tr:nth-child(2n) {
    background: #f2f2f2;
}
</style>
<style>
.el-table .selected-row-color {
    background-color: #b8dcff !important;
}
.el-table--enable-row-hover .el-table__body tr.selected-row-color:hover > td {
    background-color: #b8dcff !important;
}
.el-table__body-wrapper .el-table__body tr.selected-row-color.hover-row > td {
    background-color: #b8dcff !important;
}
.el-table__fixed-body-wrapper
    .el-table__body
    tr.selected-row-color.hover-row
    > td {
    background-color: #b8dcff !important;
}
.el-table__body-wrapper
    .el-table__body
    tr.selected-row-color.hover-row
    > .el-table__row--striped {
    background-color: #b8dcff !important;
}
</style>

